/**
*
* @description : 零售户信息列表
* @descriptionDetail : 零售户信息列表
* @copyright : 浙江烟草
* @author : zx
* @create : 2024-05-14 10:10:13
*/
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY  -->
    <theme-navbar :is-white="false" backText="返回" title="信用违规行为维护" :custom-back="goBack">
      <view class="nav-right-icon">
        <span>
          <u-icon color="#FFF" name="more-dot-fill" size="38" @tap="selectCondit"></u-icon>
        </span>
      </view>
    </theme-navbar>
    <!-- #endif -->
    <!-- #ifdef H5-DINGDING || H5-WECHAT || H5-EMP -->
    <fab-button :content="fContent" @fabtrigger="fabtrigger" />
    <!-- #endif -->
    <view class="content-list">
      <me-table :i="0" :top="0" style="padding-bottom:90px;" :index="0" :load-data="loadData" :init-load="true" ref="mescrollItem0">
        <view class="re-list" slot-scope="d">
          <u-swipe-action :index="d.index" :disabled="d.data.manualStatus != '00'" :show="contentList[d.index].showSwipe" @click="deliverClick" @open="deliverOpen" :options="cardOptions">
            <view class="re-content" @click.native="goEditOrViewYes(d.data)">
              <!-- <view class="re-manager" @click="viewRetailerDetail(d.data)"> -->
              <view class="re-manager">
                <text class="re-title">
                  {{ d.data.companyName }}
                </text>
                <u-tag style="flex-shrink: 0; height: fit-content" :spStyle="getSpStyle(d.data)" v-if="d.data.licStatus" mode="dark" shape="circle" :text="d.data.licStatusName"></u-tag>
                <text class="re-tit"></text>
              </view>
              <view class="re-subtitle">
                {{ d.data.businessAddr }}
              </view>
              <view class="re-icon">
                <u-row style="width: 100%">
                  <u-col span="6" style="padding-left: 0px">
                    <u-icon :label="d.data.managerName || ''" size="30" name="/static/check/manager.png"></u-icon>
                  </u-col>
                  <u-col span="6">
                    维护状态：{{d.data.manualStatus=='00'?'草稿':d.data.manualStatus=='01'?'提交':d.data.manualStatus=='02'?'审批中':d.data.manualStatus=='03'?'准予通过':d.data.manualStatus=='04'?'不予通过':''}}
                  </u-col>
                </u-row>
              </view>
              <view class="re-icon">
                <u-row style="width: 100%">
                  <u-col span="12">
                    违法违规日期：{{d.data.manualDate}}
                  </u-col>
                </u-row>
              </view>

              <!-- <view class="re-icon">
                <u-row style="width: 100%">
                    <u-col span="4" style="text-align: center">
                    <u-tag style="flex-shrink: 0; height: fit-content" mode="dark" shape="circle" text="编 辑" v-if="d.data.manualStatus == '00'&&user.user.personUuid==d.data.creatorUuid" @click.native="goEditOrView(d.data)"></u-tag>
                    </u-col>
                    <u-col span="4" style="text-align: center">
                    <u-tag style="flex-shrink: 0; height: fit-content" mode="dark" shape="circle" text="查 看"  @click.native="goEditOrViewYes(d.data)"></u-tag>
                    </u-col>
                    <u-col span="4" style="text-align: center">
                    <u-tag style="flex-shrink: 0; height: fit-content" type="error" mode="dark" shape="circle" v-if="d.data.manualStatus == '00'&&user.user.personUuid==d.data.creatorUuid" text="删 除" @click.native="delRetail(d.data)"></u-tag>
                    </u-col>
                </u-row>
                </view> -->
              <!-- 提示框 modelContent -->
              <u-modal v-model="modelShow" :content="modelContent" @confirm="doPhoneNew(d.data.retailTel)"></u-modal>
            </view>
          </u-swipe-action>
        </view>
      </me-table>
      <view class="submit-btns btn-other-cls">
        <u-button class="u-btn" type="primary" @click="createApply">
          信用违规行为发起
        </u-button>
      </view>
    </view>
    <u-popup v-model="queryShow" width="80%" mode="right">
      <view class="cearch_title"> 查询条件 </view>
      <u-form :model="queryForm" label-position="top" label-width="auto" style="padding: 80rpx 32rpx 160rpx 32rpx" ref="uForm">
        <u-form-item label="组织机构" right-icon="arrow-right">
          <u-input :disabled="true" placeholder="请选择" v-model="queryForm.orgName" :custom-style="pointerStyle" @click="choiceOrg">
          </u-input>
        </u-form-item>
        <u-form-item label="许可证号:">
          <u-input placeholder="请输入" v-model="queryForm.licNo" />
        </u-form-item>
        <u-form-item label="企业（字号）名称:">
          <u-input placeholder="请输入" v-model="queryForm.companyName" />
        </u-form-item>
        <u-form-item label="负责人:">
          <u-input placeholder="请输入" v-model="queryForm.managerName" />
        </u-form-item>
        <u-form-item label="修复类型:">
          <dic-input :keyWord="$u.dic.DIC_KEYS.M_REPAIR_TYPE" :dicCode="searchObj.repairType" inputAlign="left" type="select" :select-open="dicSelectOpen('repairType',$u.dic.DIC_KEYS.M_REPAIR_TYPE)"
            placeholder="请选择" v-model="searchObj.repairTypeName" @changeInputModelData="(name)=>{$set(searchObj, 'repairTypeName', name)}"
            @click="showDic($u.dic.DIC_KEYS.M_REPAIR_TYPE, searchObj.repairType, 'repairType')" />
        </u-form-item>
        <u-form-item label="修复状态:">
          <dic-input :keyWord="$u.dic.DIC_KEYS.M_REPAIR_STATUS" :dicCode="searchObj.status" inputAlign="left" type="select" :select-open="dicSelectOpen('status',$u.dic.DIC_KEYS.M_REPAIR_STATUS)"
            placeholder="请选择" v-model="searchObj.statusName" @changeInputModelData="(name)=>{$set(searchObj, 'statusName', name)}"
            @click="showDic($u.dic.DIC_KEYS.M_REPAIR_STATUS, searchObj.status, 'status')" />
        </u-form-item>
      </u-form>

      <view class="submit-btns btn-other-cls">
        <u-button plain class="u-btn" type="primary" @click="resetBtn">
          重置
        </u-button>
        <u-button class="u-btn" type="primary" @click="confirmBtn">
          确定
        </u-button>
      </view>

    </u-popup>
    <u-popup mode="bottom" height="80%" v-model="orgSelectShow">
      <org-select :cleanParentOrg="true" :isHybrid="true" limitNodeType="all" treeType="zm-all" @choose="handlerChooseOrg"></org-select>
    </u-popup>
    <u-popup mode="bottom" height="50%" v-model="dicShow">
      <dic-multi-choice :keyWord="dicKeyWords" :defaultUids="dicCurrentSelect" @select="selectDicConfirm" :otherLogic="true" :logicFun="logicFun"></dic-multi-choice>
    </u-popup>
  </view>
</template>

<script>
import MeTable from "@/components/me-table.vue";
import { AMapMixin } from "@/common/AMapMixin.js";
import dicMultiChoice from "@/components/dic_multi_choice.vue";
import dicInput from "@/components/dic_input.vue";
import fabButton from "@/components/uni-fab.vue";
import OrgSelect from "@/components/org-select.vue";
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import checkService from "@/service/check/check.service";
import { L_LIC_STATUS } from "@/service/query/mapping/enum.js";
import { SET_MAP_LAT_LON } from "@/config/setting.config.js";
const sysCodeColors = {
  "07": {
    color: "#EC7C37",
    borderColor: "#EC7C37",
    backgroundColor: "#FBE2D3"
  },
  "04": {
    color: "#01A79A",
    borderColor: "#01A79A",
    backgroundColor: "#C0ECE2"
  },
  "01": {
    color: "#AC0000",
    borderColor: "#AC0000",
    backgroundColor: "#F2CCCC"
  },
  "06": {
    color: "#FF9E2C",
    borderColor: "#FF9E2C",
    backgroundColor: "#FFF3E6"
  },
  "08": {
    color: "#0079F2",
    borderColor: "#0079F2",
    backgroundColor: "#E0ECFF"
  },
  "02": {
    color: "#717579",
    borderColor: "#717579",
    backgroundColor: "#EDEEEF"
  },
  "05": {
    color: "#20AB5C",
    borderColor: "#20AB5C",
    backgroundColor: "#DBF4E6"
  },
  "03": {
    color: "#FF9E2C",
    borderColor: "#FF9E2C",
    backgroundColor: "#FFF3E6"
  }
};
export default {
  components: {
    MeTable,
    OrgSelect,
    fabButton,
    dicInput,
    dicMultiChoice
  },
  mixins: [MescrollMoreMixin, AMapMixin],
  data() {
    let dateObj = new Date();
    let currYear = dateObj.getFullYear();
    let currMonth =
      dateObj.getMonth() + 1 > 10
        ? dateObj.getMonth() + 1
        : `0${dateObj.getMonth() + 1}`;
    let currDate =
      dateObj.getDate() > 10 ? dateObj.getDate() : `0${dateObj.getDate()}`;
    let dateBegin = `${currYear}-01-01`;
    let dateEnd = `${currYear}-${currMonth}-${currDate}`;

    let user = this.$storage.get(this.$rp.common.USER);
    let orgUuid = user.provOrgUuid;
    let orgName = user.provOrgName;
    switch (user.orgLevel) {
      // 省级
      case 1:
        orgUuid = user.provOrgUuid;
        orgName = user.provOrgName;
        break;
      // 市级
      case 2:
        orgUuid = user.cityOrgUuid;
        orgName = user.cityOrgName;
        break;
      // 县级
      case 3:
        orgUuid = user.townOrgUuid;
        orgName = user.townOrgName;
        break;
      default:
        orgUuid = user.provOrgUuid;
        orgName = user.provOrgName;
        break;
    }
    return {
      cardOptions: [
        {
          text: "编辑",
          style: {
            backgroundColor: "#007aff"
          }
        },
        {
          text: "删除",
          style: {
            backgroundColor: "#dd524d"
          }
        }
      ],
      dicShow: false,
      dicCurrentSelect: "",
      dicKeyWords: "",
      dicType: "",
      modelShow: false,
      modelContent: "",
      keyword: "",
      longitude: "",
      latitude: "",
      tels: [],
      contentList: [],
      isInterview: "",
      user: this.$storage.get(this.$rp.common.USER),
      retailData: [],
      firstNoLoad: false,
      queryShow: false,
      fContent: [
        {
          iconPath: require("@/static/sou.png"),
          selectedIconPath: require("@/static/sou.png"),
          text: "筛选",
          active: false
        }
      ],
      searchObj: {
        // areaName: "",
        // accrediDate: "",
        statusName: "",
        status: "",
        repairTypeName: "",
        repairType: ""
        // regionalization: ""
      },
      queryForm: {
        orgUuid, // 组织机构uuid
        orgName, // 组织机构名称
        licNo: "",
        companyName: "",
        managerName: "",
        repairType: "",
        repairTypeName: "",
        status: "",
        statusName: ""
      },
      orgSelectShow: false,
      // h5端部分浏览器input设置disabled后点击事件失效 2023-10-25 fsx start
      pointerStyle: {
        marginRight: "5px",
        pointerEvents: "none !important"
      }
      // showDateRange: false,
    };
  },
  onLoad(options) {
    this.isInterview = options.isInterview;
  },
  // 页面加载成功后也要设置一次，用于处理本页面刷新后失效问题
  // mounted() {
  //     this.loadData();
  // },
  methods: {
    // goEditOrView(record) {
    //   this.$u.route(
    //     "pages/check/ManualDeductionInitiated/components/addManualDeductionApply",
    //     {
    //       manualRecordUuid : record.manualRecordUuid,
    //       AddOrEdit: "edit"
    //     }
    //   );
    // },
    goEditOrViewYes(record) {
      this.$u.route(
        "pages/check/ManualDeductionInitiated/components/addManualDeductionApply",
        {
          manualRecordUuid: record.manualRecordUuid,
          AddOrEdit: "view"
        }
      );
    },
    selectCondit() {
      this.queryShow = true;
    },
    fabtrigger(btn) {
      if (btn.index == 0) {
        this.queryShow = true;
      }
    },
    initAmap() {},
    handlerSearch() {
      if (this.$u.test.isEmpty(this.keyword)) {
        this.$u.toast("请输入关键字");
        return;
      }
      this.$refs["mescrollItem0"].refresh();
    },
    getSpStyle(it) {
      if (it.licStatus == L_LIC_STATUS.SHUT_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.ORDER_SHUT_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.CANCEL_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.CLOSE_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.WITHDRAW_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.REVOKE_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.RECALL_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      } else if (it.licStatus == L_LIC_STATUS.NORMAL_STATUS) {
        return sysCodeColors[it.licStatus] || {};
      }
    },
    // 零售户列表数据查询
    loadData(page) {
      // this.longLatit()
      let self = this;
      let param = {
        orgUuid: this.queryForm.orgUuid,
        licNo: this.queryForm.licNo,
        companyName: this.queryForm.companyName,
        managerName: this.queryForm.managerName,
        repairType: this.queryForm.repairType,
        status: this.queryForm.status,
        page: page.num,
        limit: page.size
      };
      return new Promise(resolve => {
        checkService
          .queryLicIllegalManageRecordList(param)
          .then(res => {
            if (res.success) {
              let list = res.data.map(item => {
                return {
                  ...item,
                  showSwipe: false
                };
              });
              this.contentList = this.contentList.concat(list);
              resolve({
                count: res.count,
                data: [...list]
              });
            } else {
              resolve({
                count: 0,
                data: []
              });
            }
          })
          .catch(e => {
            resolve({
              count: 0,
              data: []
            });
          });
        // });
      });
    },
    // delRetail(record) {
    //   // deleteCreditRepairRecord
    //   this.$modal.alert(
    //     "您确定要删除此项吗？",
    //     "提示",
    //     () => {
    //       checkService
    //         .deleteLicIllegalManagement({
    //           manualRecordUuid: record.manualRecordUuid
    //         })
    //         .then(res => {
    //           if (res.success) {
    //             this.$modal.toast("删除成功");
    //             this.loadData({ num: "1", size: "15" });
    //             this.$refs["mescrollItem0"].refresh();
    //           } else {
    //             this.$modal.toast("删除失败");
    //           }
    //         })
    //         .catch(err => {
    //           this.$modal.toast("删除失败");
    //         });
    //     },
    //     "",
    //     true
    //   );
    //   //删除方法
    // },
    // 查看零售户详情
    viewRetailerDetail(retailer) {
      this.$u.route("pages/retailer/retailerInfo/retailerInfo", {
        retailerUuid: retailer.retailerUuid,
        licNo: retailer.licNo
      });
    },
    choiceOrg() {
      this.orgSelectShow = true;
    },
    handlerChooseOrg(orgs) {
      this.queryForm.orgUuid = orgs[0].id;
      this.queryForm.orgName = orgs[0].name;
      this.orgSelectShow = false;
    },
    confirmBtn() {
      //   this.loadData({ num: "1", size: "10" });
      this.queryShow = false;
      this.$refs["mescrollItem0"].refresh();
    },
    resetBtn() {
      this.queryForm = {};
      this.searchObj = {};
    },
    createApply() {
      this.$u.route(
        "pages/check/ManualDeductionInitiated/components/addManualDeductionApply",
        {
          AddOrEdit: "add"
        }
      );
    },
    dicSelectOpen(type, keyWords) {
      console.log(type);
      if (type == this.dicType) {
        if (this.dicKeyWords == keyWords && this.dicShow) {
          return true;
        }
        return false;
      }
    },
    showDic(key, cur, type) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
      this.dicType = type;
    },
    selectDicConfirm(e) {
      const codes = e.map(item => item.bcbCode);
      const label = e.map(item => item.bcbName).join(",");
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.M_REPAIR_TYPE) {
        // 许可证状态
        this.searchObj.repairTypeName = label;
        this.searchObj.repairType = codes.join(",");
        this.queryForm.repairType = codes.join(",");
      } else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.M_REPAIR_STATUS) {
        // 客户分类
        this.searchObj.statusName = label;
        this.searchObj.status = codes.join(",");
        this.queryForm.status = codes.join(",");
      }
      this.dicShow = false;
    },
    // 信用档位互斥逻辑函数
    logicFun(item, selectedItems) {
      if (selectedItems.length > 0) {
        selectedItems = [];
        selectedItems.push(item);
        return selectedItems;
      } else {
        selectedItems.push(item);
        return selectedItems;
      }
    },
    deliverClick(index, btnIndex) {
      let list = this.$refs.mescrollItem0.listDatas;
      let processStatus = list[index].manualStatus;
      this.deliverOpen(99999); // 无论编辑还是删除 都关闭swipe
      if (btnIndex == 0) {
        if (processStatus == "00") {
          this.$u.route(
            "pages/check/ManualDeductionInitiated/components/addManualDeductionApply",
            {
              manualRecordUuid: list[index].manualRecordUuid,
              AddOrEdit: "edit"
            }
          );
        } else {
          this.$u.toast("当前处于非草稿状态下，不可编辑");
        }
      } else {
        // 可以删除
        if (processStatus == "00") {
          let params = [list[index].id];
          this.$modal.confirm("确定要删除吗?", () => {
            checkService
              .deleteLicIllegalManagement({
                manualRecordUuid: list[index].manualRecordUuid
              })
              .then(res => {
                if (res.success) {
                  this.$modal.toast("删除成功");
                  this.loadData({ num: "1", size: "10" });
                  this.$refs["mescrollItem0"].refresh();
                } else {
                  this.$modal.toast(res.msg);
                }
              })
              .catch(err => {
                this.$modal.toast("删除失败");
              });
          });
        } else {
          this.$u.toast("当前处于非草稿状态下，不可删除");
        }
      }
    },
    deliverOpen(index) {
      this.contentList[index] ? (this.contentList[index].showSwipe = true) : "";
      this.contentList.map((val, idx) => {
        if (index != idx) this.contentList[idx].showSwipe = false;
      });
    },
    updateBackState(param) {
      if (param.SaveRefresh) {
        this.$modal.alert("保存成功");
        this.loadData({ num: "1", size: "10" });
        this.$refs["mescrollItem0"].refresh();
      }
      if (param.SubmitRefresh) {
        this.$modal.alert("提交成功");
        this.loadData({ num: "1", size: "10" });
        this.$refs["mescrollItem0"].refresh();
      }
    }
  }
};
</script>

<style lang="scss" scoped>
@import "style/certificate/common.scss";
@import "@/style/common/rightMenu.scss";

.page {
  padding: 0;
}

.content-list {
  background-color: #f3f4f5;
}

.re-list {
  margin: 20rpx;
  color: #666666;
  font-size: 15px;
  border-bottom: 1px solid #e9e9e9;
  //   display: flex;
  //   flex-direction: row;
  //   justify-content: flex-start;
  //   -webkit-flex-direction: row;
  background-color: #fff;
  border-radius: 12px;
  padding: 12px;
}

.re-media {
  padding-right: 10px;
  vertical-align: middle;
}

.re-content {
  width: 100%;

  .re-manager {
    display: flex;
    justify-content: space-between;

    .re-title {
      width: calc(90%);
      font-size: 15px;
      color: #666;
      font-weight: 600;
      margin-bottom: 5px;
      width: 80%;
    }
  }

  .re-subtitle {
    padding-top: 5px;
    color: #666;
  }

  .re-icon {
    display: flex;
    padding-top: 10px;
  }
}

/deep/.u-line {
  flex-shrink: 0;
}
.cearch_title {
  background-color: #f3f4f5;
  width: 100%;
  height: 82rpx;
  font-size: 32rpx;
  font-weight: 600;
  padding: 22rpx 0 21rpx 32rpx;
  z-index: 999;
  position: fixed;
}

.list-wrap {
  margin-top: 10rpx;
  .title {
    font-size: 32rpx;
    line-height: 80rpx;
    // border-bottom: 1rpx solid #999;
  }
}

.list {
  &-item {
    &-content {
      padding: 20rpx 0;
    }
  }
}
</style>
